const service = require('../service/user.service');

class UserController {
  async getFieldsList(ctx, next) {
    const result = await service.getFieldsList();
    await next();
    ctx.body = result;
  };

  async getquestionsRand(ctx, next) {
    const { fieldId, questionsNum } = ctx.request.query;
    const result = await service.getquestionsRand(fieldId, questionsNum);
    await next();
    ctx.body = result;
  }

  async getquestionsById(ctx, next) {
    const id = ctx.request.body.id;
    const result = await service.getquestionsById(id);
    await next();
    ctx.body = result;
  }

  async getScoreList(ctx, next) {
    const result = await service.getScoreList();
    await next();
    ctx.body = result;
  }

  async getScoreById(ctx, next) {
    const id = ctx.request.params.id;
    const result = await service.getScoreById(id);
    await next();
    ctx.body = result;
  }

  async addScore(ctx, next) {
    const { fieldId, record, score } = ctx.request.body;
    const result = await service.addScore(fieldId, record, score);
    await next();
    ctx.body = result;
  }
}

module.exports = new UserController();